﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Web.UI.WebControls;
using System.Web.UI;
using System.Web.UI.HtmlControls;

using AjaxControlToolkit;
using BizElements.Core;
using BizElements.BusinessLayer;

namespace BizElements.Web
{
    /// <summary>Represents a complex property binding, ie. a child weak or composite entity bound to a dedicated user control.</summary>
    public sealed class ComplexPropertyBinding<T> : IComplexPropertyBinding
        where T : IDataObject, new()
    {
        #region Members.

        IDataObjectUI userControl;
        Control[] decorativeControls;

        #endregion

        #region CTor.

        /// <summary>Initializes a new isntance of ComplexPropertyBinding class.</summary>
        /// <param name="propertyName">Name of the complex property.</param>
        /// <param name="userControl">User control.</param>
        /// <param name="decorativeControls">IDs of decorative controls aroun bound user control such as HR elements...</param>
        public ComplexPropertyBinding(string propertyName, IDataObjectUI userControl, params Control[] decorativeControls)
        {
            this.PropertyName = propertyName;
            this.userControl = userControl;
            this.decorativeControls = (decorativeControls != null) ? decorativeControls : new Control[0];
        }

        #endregion

        #region Properties.

        /// <summary>Name of the complex property.</summary>
        public string PropertyName { get; private set; }

        /// <summary>ID of user control that implements <see cref="IDataObjectUI"/> interface.</summary>
        public string UserControlId
        {
            get { return this.userControl.ID; }
        }

        /// <summary>IDs of decorative controls aroun bound user control such as HR elements...</summary>
        public string[] DecorativeControlIds
        {
            get
            {
                string[] ids = new string[this.decorativeControls.Length];
                for (int i = 0; i < this.decorativeControls.Length; i++)
                    ids[i] = this.decorativeControls[i].ID;

                return ids;
            }
        }

        #endregion

        #region Methods.

        /// <summary>Gets user control.</summary>
        /// <param name="parentBizobjControl">Parent user control.</param>
        /// <returns>IDataObjectUI control.</returns>
        public IDataObjectUI GetUserControl(Control parentBizobjControl)
        {
            return this.userControl;
        }

        #endregion
    }
}
